home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / internet / appc / echo.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-11-12  |  11.0 KB  |  336 lines

  1. VERSION 2.00
  2. Begin Form frmEcho 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   3  'Fixed Double
  5.    Caption         =   "Echo!"
  6.    ClientHeight    =   4920
  7.    ClientLeft      =   3705
  8.    ClientTop       =   3405
  9.    ClientWidth     =   6255
  10.    Height          =   5325
  11.    Icon            =   ECHO.FRX:0000
  12.    Left            =   3645
  13.    LinkTopic       =   "Form1"
  14.    ScaleHeight     =   4920
  15.    ScaleWidth      =   6255
  16.    Top             =   3060
  17.    Width           =   6375
  18.    Begin TextBox txtServer 
  19.       BackColor       =   &H00C0C0C0&
  20.       Height          =   315
  21.       Left            =   2550
  22.       MultiLine       =   -1  'True
  23.       TabIndex        =   13
  24.       Top             =   420
  25.       Width           =   2175
  26.    End
  27.    Begin CommandButton cmdSend 
  28.       BackColor       =   &H00C0C0C0&
  29.       Caption         =   "&Send"
  30.       Height          =   315
  31.       Left            =   4980
  32.       TabIndex        =   5
  33.       Top             =   2640
  34.       Width           =   1215
  35.    End
  36.    Begin TextBox txtReceivedData 
  37.       BackColor       =   &H00C0C0C0&
  38.       Height          =   855
  39.       Left            =   270
  40.       MultiLine       =   -1  'True
  41.       TabIndex        =   6
  42.       Top             =   3870
  43.       Width           =   4575
  44.    End
  45.    Begin TextBox txtSendData 
  46.       Height          =   855
  47.       Left            =   300
  48.       MultiLine       =   -1  'True
  49.       TabIndex        =   4
  50.       Text            =   "Hello World"
  51.       Top             =   2640
  52.       Width           =   4575
  53.    End
  54.    Begin CommandButton cmdDeallocate 
  55.       BackColor       =   &H00C0C0C0&
  56.       Caption         =   "&Deallocate (selected)"
  57.       Height          =   315
  58.       Left            =   2550
  59.       TabIndex        =   3
  60.       Top             =   1560
  61.       Width           =   2175
  62.    End
  63.    Begin CommandButton cmdAllocate 
  64.       BackColor       =   &H00C0C0C0&
  65.       Caption         =   "&Allocate (new)"
  66.       Height          =   315
  67.       Left            =   2550
  68.       TabIndex        =   2
  69.       Top             =   1200
  70.       Width           =   2175
  71.    End
  72.    Begin ListBox lstConversation 
  73.       Height          =   1005
  74.       Left            =   300
  75.       TabIndex        =   1
  76.       Top             =   1200
  77.       Width           =   2175
  78.    End
  79.    Begin ComboBox cboSystemList 
  80.       Height          =   300
  81.       Left            =   300
  82.       Style           =   2  'Dropdown List
  83.       TabIndex        =   0
  84.       Top             =   420
  85.       Width           =   1635
  86.    End
  87.    Begin CommandButton cmdExit 
  88.       BackColor       =   &H00C0C0C0&
  89.       Caption         =   "&Exit"
  90.       Height          =   315
  91.       Left            =   4980
  92.       TabIndex        =   7
  93.       Top             =   3900
  94.       Width           =   1215
  95.    End
  96.    Begin Label lblServer 
  97.       BackStyle       =   0  'Transparent
  98.       Caption         =   "Server Program"
  99.       Height          =   225
  100.       Left            =   2520
  101.       TabIndex        =   12
  102.       Top             =   120
  103.       Width           =   1455
  104.    End
  105.    Begin Label lblReceiveData 
  106.       BackStyle       =   0  'Transparent
  107.       Caption         =   "Data echoed back from the AS/400:"
  108.       Height          =   315
  109.       Left            =   300
  110.       TabIndex        =   11
  111.       Top             =   3600
  112.       Width           =   3195
  113.    End
  114.    Begin Label lblSendData 
  115.       BackStyle       =   0  'Transparent
  116.       Caption         =   "3. Enter data to send to the AS/400 and press 'Send'."
  117.       Height          =   315
  118.       Left            =   60
  119.       TabIndex        =   10
  120.       Top             =   2340
  121.       Width           =   4695
  122.    End
  123.    Begin Label lblConversations 
  124.       BackStyle       =   0  'Transparent
  125.       Caption         =   "2. Allocate one or more conversations."
  126.       Height          =   315
  127.       Left            =   60
  128.       TabIndex        =   9
  129.       Top             =   900
  130.       Width           =   3495
  131.    End
  132.    Begin Label lblSystems 
  133.       BackStyle       =   0  'Transparent
  134.       Caption         =   "1. Select a system."
  135.       Height          =   255
  136.       Left            =   60
  137.       TabIndex        =   8
  138.       Top             =   120
  139.       Width           =   1695
  140.    End
  141. Option Explicit
  142.  ' Constants:
  143.   Const nCOMM_BUFFER_SIZE = 500        ' communications buffer size
  144.  ' Variables:
  145.   Dim nPartnerMAX      As Integer      ' maximum read attempts
  146.   Dim sPartnerICF      As String       ' ICF program device
  147.   Dim sPartnerLIB      As String       ' partner library
  148.   Dim sPartnerPGM      As String       ' partner program
  149.   Dim sPartnerSYS      As String       ' partner system
  150. Sub cmdAllocate_Click ()
  151.  ' Description:
  152.  '  Allocate a BASIC conversation
  153.  ' Variables:
  154.   Static asPIPArray(1) As String      ' PIP data sent
  155.   Dim lConvID          As Long        ' conversation ID returned
  156.   Dim nRC              As Integer     ' return code received
  157.   ' is router loaded?
  158.   If zzCARouterLoaded(Me.hWnd) <> True Then
  159.     gsMBText = "The router is not loaded."
  160.     gsMBText = gsMBText & " Cannot allocate a conversation at this time."
  161.     MsgBox gsMBText, MB_ICONSTOP
  162.     Exit Sub
  163.   End If
  164.   ' is system selected?
  165.   If cboSystemList = gsEMPTY Then
  166.     MsgBox "Select a system.", MB_ICONSTOP
  167.     cboSystemList.SetFocus
  168.     Exit Sub
  169.   End If
  170.   ' setup PIP data which contains library to use
  171.   asPIPArray(0) = Left$(sPartnerLIB & Space$(10), 10)
  172.   ' allocate a BASIC conversation
  173.   lConvID = zzCAConvStartBasic(Me.hWnd, nCOMM_BUFFER_SIZE, cboSystemList, Trim$(sPartnerLIB) & "/" & Trim$(sPartnerPGM), zzCAFormattedPIP(Me.hWnd, asPIPArray()), nRC)
  174.   ' if started then add to list
  175.   If lConvID <> 0 Then
  176.     lstConversation.AddItem Str$(lConvID)
  177.     lstConversation.ListIndex = lstConversation.ListCount - 1
  178.   End If
  179. End Sub
  180. Sub cmdDeallocate_Click ()
  181.  ' Description:
  182.  '  Deallocate a BASIC conversation
  183.   ' remove selected conversation
  184.   If Val(lstConversation) <> 0 Then
  185.     If zzCAConvStopFlush(Me.hWnd, Val(lstConversation)) = gnCA_OK Then
  186.       lstConversation.RemoveItem lstConversation.ListIndex
  187.     Else
  188.     End If
  189.   End If
  190. End Sub
  191. Sub cmdExit_Click ()
  192.   ' end program
  193.   Unload Me
  194. End Sub
  195. Sub cmdSend_Click ()
  196.  ' Description:
  197.  '  Send a record
  198.  ' Variables:
  199.   Dim bCAPartnerWishesToSend As Integer      ' partner wishes to send
  200.   Dim nCArc                  As Integer      ' API return code
  201.   Dim sCAData                As String       ' data
  202.   Dim nCAWhatRcvd            As Integer      ' what is being sent back
  203.   Dim sCADataBlock           As String       ' data block
  204.   ' select a conversation
  205.   If Val(lstConversation) = 0 Then
  206.     MsgBox "Select a conversation", MB_ICONSTOP
  207.     Exit Sub
  208.   End If
  209.   ' tell partner I'm want to send
  210.   nCArc = zzCATellWantToSend(Me.hWnd, Val(lstConversation))
  211.   ' send information
  212.   nCArc = zzCASendBasic(Me.hWnd, Val(lstConversation), txtSendData, Len(txtSendData), bCAPartnerWishesToSend)
  213.   ' tell partner I'm ready to receive
  214.   nCArc = zzCATellReadyToReceive(Me.hWnd, Val(lstConversation))
  215.   sCADataBlock = gsEMPTY
  216.   Screen.MousePointer = HOURGLASS
  217.   cmdSend.Enabled = False
  218.   ' loop to get returned information
  219.     ' receive record
  220.     nCArc = zzCAReceiveBasic(Me.hWnd, Val(lstConversation), Len(txtSendData), sCAData, nCAWhatRcvd, bCAPartnerWishesToSend)
  221.     DoEvents
  222.     ' action based on return code
  223.     Select Case nCArc
  224.       
  225.       ' everything OK
  226.       Case gnCA_OK
  227.         
  228.         ' if partner said ready to receive more then exit loop
  229.         If nCAWhatRcvd = gnCA_RCVD_SEND Then
  230.           Exit Do
  231.         
  232.         ' else add data to block
  233.         Else
  234.           sCADataBlock = sCADataBlock & sCAData
  235.         End If
  236.       
  237.       ' don't show message on busy, or unsuccessful
  238.       Case gnCA_APPC_BUSY, gnCA_UNSUCCESSFUL
  239.       
  240.       ' show any other error
  241.       Case Else
  242.         MsgBox zzCAGetRCText(nCArc, True), MB_ICONSTOP
  243.         Screen.MousePointer = DEFAULT
  244.         cmdSend.Enabled = True
  245.         Exit Sub
  246.     End Select
  247.   Loop
  248.   ' put data returned into text box
  249.   Screen.MousePointer = DEFAULT
  250.   cmdSend.Enabled = True
  251.   txtReceivedData.Text = Mid$(sCADataBlock, gnCA_BASIC_HEADER_LEN + 1, Len(sCADataBlock) - gnCA_BASIC_HEADER_LEN)
  252. End Sub
  253. Sub Form_Load ()
  254.  ' Variables:
  255.   Dim n1             As Integer    ' loop counter
  256.   ' setup global variables
  257.   Call zzSetGlobalVariables
  258.   ' center form
  259.   zzFormCenter Me
  260.   ' setup title
  261.   App.Title = Caption
  262.   ' setup INI file and section
  263.   n1 = zzINISetFile(App.Path & "\APPC.INI")
  264.   n1 = zzINISetSection("ECHO")
  265.   ' get AS/400 system
  266.   n1 = zzINIGetString("System", sPartnerSYS)
  267.   ' get AS/400 library
  268.   n1 = zzINIGetString("Library", sPartnerLIB)
  269.   If sPartnerLIB = gsEMPTY Then
  270.     MsgBox "AS/400 library reference invalid. Check APPC.INI files for proper values."
  271.     End
  272.   End If
  273.   ' get AS/400 program
  274.   n1 = zzINIGetString("Program", sPartnerPGM)
  275.   If sPartnerPGM = gsEMPTY Then
  276.     MsgBox "AS/400 program reference invalid. Check APPC.INI files for proper values."
  277.     End
  278.   End If
  279.   ' get AS/400 ICF device
  280.   n1 = zzINIGetString("Device", sPartnerICF)
  281.   If sPartnerICF = gsEMPTY Then
  282.     MsgBox "AS/400 ICF device reference invalid. Check APPC.INI files for proper values."
  283.     End
  284.   End If
  285.   ' get maximum read attempts
  286.   n1 = zzINIGetInteger("MaxAttempts", nPartnerMAX)
  287.   If nPartnerMAX = 0 Then
  288.     MsgBox "APPC retry attempts setting invalid. Check APPC.INI files for proper values."
  289.     End
  290.   End If
  291.   ' show server program
  292.   txtServer = sPartnerLIB & "/" & sPartnerPGM
  293.   ' if router loaded
  294.   If zzCARouterLoaded(Me.hWnd) = True Then
  295.     ' put list into control
  296.     Call zzCAPutSystemListIntoCtrl(Me.hWnd, cboSystemList)
  297.     ' see if match found
  298.     For n1 = 0 To cboSystemList.ListCount - 1
  299.       If cboSystemList.List(n1) = sPartnerSYS Then
  300.         cboSystemList.ListIndex = n1
  301.         Exit For
  302.       End If
  303.     Next
  304.   End If
  305. End Sub
  306. Sub Form_QueryUnload (Cancel As Integer, UnloadMode As Integer)
  307.  ' Variables:
  308.   Dim n1 As Integer   ' loop counter
  309.   ' if conversations active
  310.   If lstConversation.ListCount <> 0 Then
  311.     ' ask user if they want to dellocate and leave
  312.     If MsgBox("Deallocate conversations?", MB_ICONQUESTION Or MB_YESNO) = IDYES Then
  313.       ' end all conversations
  314.       Screen.MousePointer = HOURGLASS
  315.       For n1 = (lstConversation.ListCount - 1) To 0 Step -1
  316.         If zzCAConvStopFlush(Me.hWnd, Val(lstConversation.List(n1))) = gnCA_OK Then
  317.           lstConversation.RemoveItem n1
  318.           lstConversation.Refresh
  319.         End If
  320.       Next
  321.       Screen.MousePointer = DEFAULT
  322.     ' do not end
  323.     Else
  324.       Cancel = True
  325.     End If
  326.   End If
  327. End Sub
  328. Sub txtReceivedData_GotFocus ()
  329.   ' cannot goto data returned
  330.   cmdExit.SetFocus
  331. End Sub
  332. Sub txtServer_GotFocus ()
  333.   ' cannot goto this field
  334.   cmdAllocate.SetFocus
  335. End Sub
  336.